// pages/report/index.js
const App = getApp()
import moment from '../../utils/moment'
import Toast from '../../weapp/toast/toast';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    show: false,
    currentDate: new Date().getTime(),
    minDate: new Date().getTime(),
    info: {},
    fileList: [],
    report_form: {
      remind_id: '',
      project: '',
      inspect_time: '',
      content: ''
    },
    formatter(type, value) {
      if (type === 'year') {
        return `${value}年`;
      } 
      if (type === 'month') {
        return `${value}月`;
      }
      if (type === 'day') {
        return `${value}日`;
      }
      if (type === 'hour') {
        return `${value}时`;
      }
      if (type === 'minute') {
        return `${value}分`;
      }
      return value;
    },
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    this.getInspectRemind(options.id)
    this.setData({
      ...this.data.report_form,
      'report_form.remind_id': options.id
    })
  },
  onChange(e) {
    let { input } = e.currentTarget.dataset
    this.setData({
      report_form: {
        ...this.data.report_form,
        [input]: e.detail
      },
      summary_form: {
        ...this.data.summary_form,
        [input]: e.detail
      }
    })
  },
  onCancel() {
    this.setData({
      show: false
    })
  },
  handleInput(e) {
    // let { type } = e.currentTarget.dataset
    this.setData({
      show: true
    })
  },
  onConfirm(event) {
    console.log(event)
    let type = event.currentTarget.dataset.type
    let { value, index } = event.detail
    this.setData({
      show: false
    })
  },
  onInput(event) {
    this.setData({
      ...this.data.report_form,
      'report_form.remind_time': moment(event.detail).format("YYYY-MM-DD HH:mm:ss"),
    });
  },


  //预约修改
  handleSave() {
    let { project, content } = this.data.report_form
    if (project == '') {
      Toast.fail('项目名不能为空')
      return false
    }
    if (content == '') {
      Toast.fail('跟进内容不能为空')
      return false
    }
    App._post('customer/editInspectRemind', this.data.report_form, function (result) {
      if (result.code === 0) {
        Toast({
          type: 'success',
          message: '提交成功',
          onClose: () => {
            wx.switchTab({
              url: '../index/index?val=2',
            })
          },
        });
      } else {
        Toast.fail(result.msg);
      }
    })
  },
  //带看预约信息
  getInspectRemind(id) {
    let _this = this
    App._post_form('customer/getInspectRemind', {
      remind_id: id
    }, function (result) {
      _this.setData({
        report_form: result.data
      })
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})